def f(x):
    for i in range(2, int(x**0.5)+1):
        if x % i == 0:
            return False
    return True
    
c = ''
wrong = 0
for i in input().split():
    if i == "zero":
        c += '0'
    elif i == "one":
        c+= '1'
    elif i == "two":
        c+= '2'
    elif i == "three":
        c+= '3'
    elif i == "four":
        c+= '4'
    elif i == "five":
        c+= '5'
    elif i == "six":
        c+= '6'
    elif i== "seven":
        c+= '7'
    elif i== "eight":
        c+= '8'
    elif i== "nine":
        c+= '9'
    else:
        wrong= 1
        break
    
if wrong == 1 or len(c) != 3:
    print("Wrong input")
else:
    c = int(c)

    m1 = 0
    m2 = 0
    
    for i in range(c+1, 1000):
        if f(i):
            m2 = i
            break
        
    for i in range(c-1, 99, -1):
        if f(i):
            m1 = i
            break
    
    if c-m1 > m2-c:
        print(m2)
    else:
        print(m1)
